package antlr.calc;


import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.TokenStreamRewriter;
import org.antlr.v4.runtime.tree.TerminalNode;

public class MyReplaceVisitor extends CalcBaseVisitor<Integer> {

    public TokenStreamRewriter rewriter;

    public MyReplaceVisitor(TokenStream s) {
        rewriter = new TokenStreamRewriter(s);
    }

    @Override
    public Integer visitOp(CalcParser.OpContext ctx) {
        TerminalNode add = ctx.ADD();
        if (add != null) {
            rewriter.replace(add.getSymbol(), " 加 ");

        }
        return super.visitOp(ctx);
    }
}
